/*******************************************************************************
 * $Header: /cvsroot/oloa/org.gocom.bpm.platform.model/src/org/gocom/bpm/platform/model/web/taglib/ConnectionImpl.java,v 1.1 2011/07/03 02:30:16 hufulai Exp $
 * $Revision: 1.1 $
 * $Date: 2011/07/03 02:30:16 $
 *
 *==============================================================================
 *
 * Copyright (c) 2001-2006 Primeton Technologies, Ltd.
 * All rights reserved.
 * 
 * Created on 2010-5-26
 *******************************************************************************/

package com.atozsoft.wf.taglib;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import com.primeton.workflow.model.definition.Transition;



public class ConnectionImpl implements Connection{
    StateImpl fromState;
    
    StateImpl toState;
    
    int type;
    
    private int causeActInsID;
    
    private String description;
    
    public List midPoints;
    
    private HashMap hm;

    public ConnectionImpl(Transition transition)
    {
        causeActInsID = -1;
        description = "";
        midPoints = new ArrayList();
        hm = new HashMap();
        com.primeton.workflow.model.definition.Activity fromActivity = transition.getProcess().findActivity(transition.getFrom());
        com.primeton.workflow.model.definition.Activity toActivity = transition.getProcess().findActivity(transition.getTo());
        setFromState(new StateImpl(fromActivity));
        setToState(new StateImpl(toActivity));
        description = transition.getName();
        HashMap extendAttribute = transition.getExtendAttribute();
        if(extendAttribute.get("extend-nodes") != null)
        {
            Iterator keys = extendAttribute.keySet().iterator();
            while(keys.hasNext())
            {
                Object key = keys.next();
                if(!key.equals("extend-nodes"))
                    hm.put(key, extendAttribute.get(key));
            } 
        } 
        else
        {
            hm = extendAttribute;
        }
    }

    public String getFromStateID()
    {
        return getFromState().getID();
    }

    public String getToStateID()
    {
        return getToState().getID();
    }

    public Point getMidPoints()
    {
        return null;
    }

    public int getType()
    {
        return type;
    }

    public String getDescription()
    {
        return description;
    }

    public String toString()
    {
        String ret = "";
        ret = (new StringBuilder()).append(ret).append(" fromStateID= ").append(getFromStateID()).toString();
        ret = (new StringBuilder()).append(ret).append(" toStateID = ").append(getToStateID()).toString();
        ret = (new StringBuilder()).append(ret).append(" type = ").append(String.valueOf(type)).toString();
        ret = (new StringBuilder()).append(ret).append(" description = ").append(description).toString();
        return ret;
    }

    public int getCauseActInstID()
    {
        return causeActInsID;
    }

    public void setCauseActInsID(int ActivityID)
    {
        causeActInsID = ActivityID;
    }

    public void setType(int type)
    {
        this.type = type;
    }

    public HashMap getHm()
    {
        return hm;
    }

    public StateImpl getFromState()
    {
        return fromState;
    }

    public void setFromState(StateImpl fromState)
    {
        this.fromState = fromState;
    }

    public StateImpl getToState()
    {
        return toState;
    }

    public void setToState(StateImpl toState)
    {
        this.toState = toState;
    }


}
